import * as vscode from "vscode";
import { VsCodeWebviewProtocol } from "./webviewProtocol";
export class HarmonyPilotGUIWebviewViewProvider implements vscode.WebviewViewProvider {

    private _webview?: vscode.Webview;
    public webviewProtocol: VsCodeWebviewProtocol;

    get webview() {
        return this._webview;
      }

    constructor(private readonly _extensionUri: vscode.Uri) {
        this.webviewProtocol = new VsCodeWebviewProtocol(this._webview);
    }

    resolveWebviewView(webviewView: vscode.WebviewView) {
        this._webview = webviewView.webview;
        this.webviewProtocol._webview = this._webview;
        webviewView.webview.options = {
            // 在 webview 允许脚本
            enableScripts: true,
            localResourceRoots: [this._extensionUri],
          };
        webviewView.webview.html = this.getDebugHtml();
    }

    getHtmlForWebview(webview: vscode.Webview) {
        return `
        <!DOCTYPE html>
        <html>
            <head>
                <title>HarmonyPilot</title>
            </head>
            <body>
                <h1>HarmonyPilot</h1>
            </body>
        </html>`
    }

    getDebugHtml() {
        return `
        <!DOCTYPE html>
        <html>
            <head>
                <title>HarmonyPilot</title>
                <link rel="stylesheet" href="http://localhost:5174/node_modules/@devui-design/icons/icomoon/devui-icon.css">
                <link rel="stylesheet" href="http://localhost:5174/src/style.css">
            </head>
            <body>
                <div id="app"></div>
                <script type="module" src="http://localhost:5174/src/main.ts"></script>
                <script>
                window.staticPath = "http://localhost:5174/";
                window.vscode = acquireVsCodeApi && acquireVsCodeApi();
                </script>
            </body>
        </html>`;
    }
        
}
